package mercado.ab;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CxVenda.java
 *
 * Created on 18/07/2011, 20:30:02
 */


import Beans.Funcionario;
import Beans.Produto;
import Beans.Venda;
import DataBase.FuncDAO;
import DataBase.ProdutoDAO;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.PrintJob;
import java.awt.Toolkit;
import java.io.PrintStream;
import java.util.Calendar;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author monitor
 */
public class CxVenda extends javax.swing.JFrame {
    

    /** Creates new form CxVenda */
    public CxVenda() {
        initComponents();
        status.setText("ATIVO");
        data.setText(ProdutoDAO.obterData());
        hora.setText(ProdutoDAO.obterHora().substring(11,16));
        //setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        //setLocationRelativeTo(null);
        //setResizable(true);
        //setVisible(true);
    }
        Double subTotal = 1.0;
        double total = 0.0;
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        txtMesa = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        status = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        data = new javax.swing.JTextField();
        hora = new javax.swing.JTextField();
        txtP = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        codigo1 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        Nome_funcionario = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        codigo2 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        dProduto = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        quant = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        valor = new javax.swing.JTextField();
        Adicionar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblVenda = new javax.swing.JTable();
        jLabel12 = new javax.swing.JLabel();
        txtSubTotal = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        txtGarcom = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        txtCover = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        txtDesconto = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        txtTotal = new javax.swing.JTextField();
        bt_encerrar = new javax.swing.JButton();
        bt_printer = new javax.swing.JButton();
        bt_fechar = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        btnAtualizar = new javax.swing.JButton();
        tipo = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBounds(new java.awt.Rectangle(600, 700, 600, 700));

        jLabel1.setText("Nº MESA");

        txtMesa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtMesaActionPerformed(evt);
            }
        });
        txtMesa.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtMesaFocusLost(evt);
            }
        });

        jLabel2.setText("STATUS");

        status.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                statusActionPerformed(evt);
            }
        });

        jLabel3.setText("DATA");

        jLabel4.setText("HORA");

        jLabel5.setText("Nº PEDIDO");

        data.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dataActionPerformed(evt);
            }
        });

        hora.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                horaActionPerformed(evt);
            }
        });

        txtP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPActionPerformed(evt);
            }
        });

        jLabel6.setText("CÓDIGO GARÇOM");

        codigo1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                codigo1FocusLost(evt);
            }
        });

        jLabel7.setText("NOME DO FUNCIONÁRIO");

        jLabel8.setText("CÓDIGO PRODUTO");

        codigo2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                codigo2ActionPerformed(evt);
            }
        });
        codigo2.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                codigo2FocusLost(evt);
            }
        });

        jLabel9.setText("DESCRIÇÃO DO PRODUTO");

        dProduto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dProdutoActionPerformed(evt);
            }
        });

        jLabel10.setText("QUANTIDADE");

        jLabel11.setText("VALOR");

        Adicionar.setText("ADICIONAR");
        Adicionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AdicionarActionPerformed(evt);
            }
        });

        tblVenda.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "REGISTRO", "DESCRIÇÃO", "QUANTIDADE", "VL. UNITÁRIO", "TOTAL"
            }
        ));
        jScrollPane1.setViewportView(tblVenda);

        jLabel12.setText("SUB-TOTAL");

        txtSubTotal.setText("0.00");
        txtSubTotal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtSubTotalActionPerformed(evt);
            }
        });

        jLabel14.setText("GARÇOM 0%");

        txtGarcom.setText("0");
        txtGarcom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtGarcomActionPerformed(evt);
            }
        });

        jLabel15.setText("COVER");

        txtCover.setText("0.00");

        jLabel16.setText("DESCONTO 0%");

        txtDesconto.setText("0");
        txtDesconto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDescontoActionPerformed(evt);
            }
        });

        jLabel17.setText("TOTAL A PAGAR");

        txtTotal.setText("0.00");
        txtTotal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtTotalActionPerformed(evt);
            }
        });

        bt_encerrar.setText("ENCERRAR");
        bt_encerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_encerrarActionPerformed(evt);
            }
        });

        bt_printer.setText("IMPRIMIR");
        bt_printer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_printerActionPerformed(evt);
            }
        });

        bt_fechar.setText("FECHAR");
        bt_fechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_fecharActionPerformed(evt);
            }
        });

        jButton6.setText("TRANSFERIR MESA");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        btnAtualizar.setText("ATUALIZAR");
        btnAtualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAtualizarActionPerformed(evt);
            }
        });

        jLabel13.setText("TIPO");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(codigo1, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(Nome_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(60, 60, 60)
                .addComponent(Adicionar, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnAtualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 720, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(layout.createSequentialGroup()
                .addGap(87, 87, 87)
                .addComponent(bt_encerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(13, 13, 13)
                .addComponent(bt_printer, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(bt_fechar, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton6))
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(codigo2, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(dProduto, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20)
                        .addComponent(valor, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20)
                        .addComponent(tipo, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(28, 28, 28)
                        .addComponent(jLabel9)
                        .addGap(173, 173, 173)
                        .addComponent(jLabel11)
                        .addGap(67, 67, 67)
                        .addComponent(jLabel13)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(quant, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txtMesa, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(status, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(data, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(51, 51, 51)
                        .addComponent(jLabel2)
                        .addGap(119, 119, 119)
                        .addComponent(jLabel3)))
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(121, 121, 121)
                        .addComponent(jLabel5))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(hora, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(txtP, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))))
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txtSubTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20)
                        .addComponent(txtGarcom, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20)
                        .addComponent(txtCover, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(txtDesconto, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addGap(95, 95, 95)
                        .addComponent(jLabel14)
                        .addGap(76, 76, 76)
                        .addComponent(jLabel15)
                        .addGap(106, 106, 106)
                        .addComponent(jLabel16)))
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel17)
                    .addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(jLabel2))
                    .addComponent(jLabel3)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(jLabel4)))
                .addGap(5, 5, 5)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(txtMesa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(status, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(hora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(data, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel6)
                        .addGap(6, 6, 6)
                        .addComponent(codigo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel7)
                        .addGap(6, 6, 6)
                        .addComponent(Nome_funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(Adicionar, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAtualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(3, 3, 3)
                                .addComponent(jLabel11))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(3, 3, 3)
                                .addComponent(jLabel13)))
                        .addGap(5, 5, 5))
                    .addComponent(jLabel10))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(codigo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(valor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(quant, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(19, 19, 19)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addComponent(jLabel14)
                    .addComponent(jLabel15)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel16)
                        .addComponent(jLabel17)))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtSubTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtGarcom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCover, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDesconto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(60, 60, 60)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(bt_encerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bt_printer, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bt_fechar, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtGarcomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtGarcomActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtGarcomActionPerformed

    private void txtSubTotalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtSubTotalActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtSubTotalActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

       /* if (Integer.parseInt(quant.getText()) != 0) {

            System.out.println("dados do adicionar " + Integer.parseInt(quant.getText()) + "valor inserido" + valor.getText());

            try {

                Prod pd = new Prod();
                String nomeProd = codigo2.getText();
                System.out.println(pd.getQuantProd((nomeProd)));
                if ((pd.getQuantProd(nomeProd)) != 0) {

                   if (pd.getQuantProd(nomeProd) >= Integer.parseInt(quant.getText())) {
                        Produto p = new Produto();

                        p.setCodigo(codigo2.getText());
                        p.setNome(dProduto.getText());
                        p.setPreco(Float.parseFloat(valor.getText()));
                    //    pd.vendaTemp(p);

                        DefaultTableModel modelo = new DefaultTableModel(0, 4);
                      //  List<Produto> listaVenda = pd.ListarVenda();
                        String[] linha = new String[5];
                        String[] colunas = new String[5];

                        //Define o nome das colunas da tabela Modelo
                        


                       // Itens i = new Itens();
                        
                       // i.setQuantidade(quant.getText());
                       // i.setPreco(valor.getText());
                       // pd.vendaTemp(i);

                        colunas[0] = ("CÓDIGO");
                        colunas[1] = ("DESCRIÇÃO");
                        colunas[2] = ("QUANTIDADE");
                        colunas[3] = ("VL.UNIT");
                        colunas[4] = ("TOTAL");
                        modelo.setColumnIdentifiers(colunas);
                        Double totalVenda = 0.0;


                   //     for (Produto pv : listaVenda) {

                      //      linha[0] = pv.getCodigo();
                      //      System.out.println(pv.getCodigo());
                       //     linha[1] = pv.getNome();
                      //      System.out.println(pv.getNome());
                      //      modelo.addRow(linha);
                      //  }
                        
                        tblVenda.setModel(modelo);

                    } else {
                        JOptionPane.showMessageDialog(null, "Quantidade no estoque Insuficiente ");
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "Produto em falta no estoque ");
                }


            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, "Exceção na tentativa de venda" + ex);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Quantidade \n não Informada", "erro", JOptionPane.ERROR_MESSAGE);

        }        // TODO add your handling code here:*/
    }//GEN-LAST:event_jButton1ActionPerformed

    private void codigo1FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_codigo1FocusLost
      try{
        FuncDAO g = new FuncDAO();
        Funcionario f = g.consultarBdFunc(codigo1.getText());
        Nome_funcionario.setText(f.getNome()+"");

      }catch(Exception ex){
          System.out.println("ERRO"+ ex);
      }
        System.out.println("DEU CERTO CONSULTAR FUNCIONARIO");
    }//GEN-LAST:event_codigo1FocusLost

    private void codigo2FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_codigo2FocusLost
        
        try {
            ProdutoDAO cv = new ProdutoDAO();
            Produto cd = cv.consultarBd(codigo2.getText());
            dProduto.setText(cd.getNome() + "");
            tipo.setText(cd.getTipo() + "");
            valor.setText(cd.getPreco()+ "");
           
            cv.Desconectar();

        } catch (Exception ex) {
            System.out.println("ERRO" + ex);
        }       
        System.out.println( "Deu certo consultar o Produto");
    }//GEN-LAST:event_codigo2FocusLost

    private void dataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dataActionPerformed
        Calendar.getInstance();
    }//GEN-LAST:event_dataActionPerformed

private void btnAtualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAtualizarActionPerformed
  if (Integer.parseInt(txtMesa.getText()) != 0) {

            //System.out.println("dados " + Double.parseDouble(quant.getText()) + "" + valor.getText());

            try {

                Prod pd = new Prod();
                //pd.AtualizarTabela (codigo2.getText(),dProduto.getText(),quant.getText(),valor.getText(),txtMesa.getText(),hora.getText(),data.getText(),Nome_funcionario.getText());
                //String nomeProd = codigo2.getText();
                //System.out.println(pd.getQuantProd(nomeProd));
                // System.out.println(nomeProd);
                     Produto p = new Produto();
                       // p.setCodigo(codigo2.getText());
                       // p.setNome(dProduto.getText());
                       // p.setQuantidade(Double.parseDouble(quant.getText()));
                       // p.setPreco(Double.parseDouble(valor.getText()));
                       //pd.ListarVenda(p.getCodigo(),p.getNome(),p.getQuantidade()+"",p.getPreco()+"",txtMesa.getText(),hora.getText(),data.getText(),Nome_funcionario.getText());

                        DefaultTableModel modelo = new DefaultTableModel(0, 4);
                        List<Produto> listaVenda = pd.ListarVenda(txtMesa.getText());
                        String[] linha = new String[5];
                        String[] colunas = new String[5];

                        //Define o nome das colunas da tabela Modelo
                        colunas[0] = ("CÓDIGO");
                        colunas[1] = ("DESCRIÇÃO");
                        colunas[2] = ("QUANTIDADE");
                        colunas[3] = ("VL.UNIT");
                        colunas[4] = ("TOTAL");
                        modelo.setColumnIdentifiers(colunas);
                        Double totalVenda = 0.0;

                        for (Produto pv : listaVenda) {

                        linha[0] = pv.getCodigo()+"";
                        System.out.println(pv.getCodigo());
                        linha[1] = pv.getNome();
                        System.out.println(pv.getNome());
                        linha[2] = pv.getQuantidade()+"";
                        System.out.println(pv.getQuantidade());
                        linha[3] = pv.getPreco()+ "";
                        System.out.println(pv.getPreco());
                        pv.setTotalProduto(pv.getQuantidade() * pv.getPreco());
                        totalVenda += pv.getTotalProduto();
                        linha[4] = pv.getTotalProduto()+ "";
                        System.out.println(totalVenda);
                        modelo.addRow(linha);

                        // txtSubTotal.setText(subTotal+"");
                         txtSubTotal.setText(totalVenda+"");

                         total = totalVenda + Double.parseDouble(txtGarcom.getText()) * totalVenda / 100 + Double.parseDouble(txtCover.getText()) - Double.parseDouble(txtDesconto.getText()) * totalVenda / 100;
                         txtTotal.setText(total + "");
                    }
                         tblVenda.setModel(modelo);
                   
              
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, "Exceção na tentativa de venda  " + ex);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Quantidade \n não Informada", "erro", JOptionPane.ERROR_MESSAGE);
        }       
}//GEN-LAST:event_btnAtualizarActionPerformed

private void bt_printerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_printerActionPerformed
   String Data = data.getText();
   String Mesa = txtMesa.getText();
   String Pedido = txtP.getText();
   String SubTotal = txtSubTotal.getText();
   String Desconto = txtDesconto.getText();
   String Total = txtP.getText();
   
      
   Frame f = new Frame("Frame temporário");      
   f.pack();       
      
   // pega o Toolkit do Frame      
   Toolkit tk = f.getToolkit();       
  
   // Pega os serviços de impressão existentes no computador,      
   // para que seja escolhida uma impressora.     
   // Também pode ser uma impressora de rede    
   PrintJob pj = tk.getPrintJob(f,  "print" , null);     
  
   // Aqui se inicia a impressão    
   if (pj != null) {     
         Graphics g = pj.getGraphics();   
               g.drawString( "Conta Impressa " , 50, 30);
               g.drawString( "Data: " + data.getText(), 50, 50);
               g.setFont(new Font("Courier New",Font.PLAIN,12));     
               g.drawString( "Mesa: " + txtMesa.getText() , 50, 70);
               g.drawString( "Pedido: " + txtP.getText() , 50, 90);
               g.drawString( "Sub-Total: " + txtSubTotal.getText() , 50, 110);
               g.drawString( "Desconto: " + txtDesconto.getText() , 50, 130);
               g.drawString( "Total: " + txtP.getText() , 50, 150);
      
       // libera os recursos gráficos     
      g.dispose();       
      // encerra a impressão     
      pj.end();    
   }     
   // desfaz o frame temporário    
   f.dispose();    
   // Método main para teste     
 
}//GEN-LAST:event_bt_printerActionPerformed

private void bt_encerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_encerrarActionPerformed

    // TODO add your handling code here:
}//GEN-LAST:event_bt_encerrarActionPerformed

private void bt_fecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_fecharActionPerformed

    System.exit(0);
    // TODO add your handling code here:
}//GEN-LAST:event_bt_fecharActionPerformed

private void txtTotalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtTotalActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_txtTotalActionPerformed

private void AdicionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AdicionarActionPerformed
    if (Integer.parseInt(quant.getText()) != 0) {

            System.out.println("dados " + Double.parseDouble(quant.getText()) + "" + valor.getText());
             
            try {

                Prod pd = new Prod();
                pd.AtualizarTabela (codigo2.getText(),dProduto.getText(),quant.getText(),valor.getText(),txtMesa.getText(),hora.getText(),data.getText(),Nome_funcionario.getText(),txtP.getText());
                String nomeProd = codigo2.getText();
                System.out.println(pd.getQuantProd(nomeProd));
                System.out.println(nomeProd);

                  
                        
                        Produto p = new Produto();

                        p.setCodigo(codigo2.getText());
                        p.setNome(dProduto.getText());
                        p.setQuantidade(Double.parseDouble(quant.getText()));
                        p.setPreco(Double.parseDouble(valor.getText()));
                        //pd.ListarVenda(p.getCodigo(),p.getNome(),p.getQuantidade()+"",p.getPreco()+"",txtMesa.getText(),hora.getText(),data.getText(),Nome_funcionario.getText());

                        DefaultTableModel modelo = new DefaultTableModel(0, 4);
                        List<Produto> listaVenda = pd.ListarVenda(txtMesa.getText());
                        String[] linha = new String[5];
                        String[] colunas = new String[5];

                        //Define o nome das colunas da tabela Modelo
                        colunas[0] = ("CÓDIGO");
                        colunas[1] = ("DESCRIÇÃO");
                        colunas[2] = ("QUANTIDADE");
                        colunas[3] = ("VL.UNIT");
                        colunas[4] = ("TOTAL");
                        modelo.setColumnIdentifiers(colunas);
                        Double totalVenda = 0.0;

                        for (Produto pv : listaVenda) {

                        linha[0] = pv.getCodigo()+"";
                        System.out.println(pv.getCodigo());
                        linha[1] = pv.getNome();
                        System.out.println(pv.getNome());
                        linha[2] = pv.getQuantidade()+"";
                        System.out.println(pv.getQuantidade());
                        linha[3] = pv.getPreco()+ "";
                        System.out.println(pv.getPreco());
                        pv.setTotalProduto(pv.getQuantidade() * pv.getPreco());
                        totalVenda += pv.getTotalProduto();
                        linha[4] = pv.getTotalProduto()+ "";
                        System.out.println(totalVenda);
                        modelo.addRow(linha);
                     
                        // txtSubTotal.setText(subTotal+"");
                         txtSubTotal.setText(totalVenda+"");
                         
                         total = totalVenda + Double.parseDouble(txtGarcom.getText()) * totalVenda / 100 + Double.parseDouble(txtCover.getText()) - Double.parseDouble(txtDesconto.getText()) * totalVenda / 100;
                         txtTotal.setText(total + "");
                    }
                         tblVenda.setModel(modelo);
                    
              
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, "Exceção na tentativa de venda" + ex);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Quantidade \n não Informada", "erro", JOptionPane.ERROR_MESSAGE);
        }        // TODO add your handling code here:
                                           
 // TODO add your handling code here:
}//GEN-LAST:event_AdicionarActionPerformed

private void txtPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_txtPActionPerformed

private void statusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_statusActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_statusActionPerformed

private void horaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_horaActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_horaActionPerformed

private void txtMesaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtMesaActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_txtMesaActionPerformed

private void dProdutoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dProdutoActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_dProdutoActionPerformed

private void txtMesaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMesaFocusLost
    try{
        ProdutoDAO g = new  ProdutoDAO();
        Venda f = g.consultarBdTbvenda(txtMesa.getText());
        txtP.setText(f.getPedido()+"");
   
      }catch(Exception ex){
           JOptionPane.showMessageDialog(null,"Sua mesa não pode ser alterada tente uma mesa Válida");   
          System.out.println("ERRO"+ ex);
      }
        System.out.println("DEU CERTO CONSULTAR FUNCIONARIO");
}//GEN-LAST:event_txtMesaFocusLost

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed

    String numero = null;
    if ((!txtMesa.getText().equals("")) ) {
            try {
                ProdutoDAO pdao = new ProdutoDAO();
                Venda p = new Venda();
                p.setMesa(txtMesa.getText());
                numero = JOptionPane.showInputDialog(null, "Digite aqui sua nova mesa?" );
         if (pdao.alterarTabela(p,numero)) {
                System.out.println(numero  + "  Sua mesa foi alterada com sucesso");
                 JOptionPane.showMessageDialog(null,"Sua mesa foi alterada com sucesso");   
            if (numero == null || numero.equals("")) {
                               JOptionPane.showMessageDialog(null,"Você não respondeu a pergunta.");
                      }   
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                System.out.println("Exceção cadastrar " + ex);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Existe Campos Vazios");
        }
}//GEN-LAST:event_jButton6ActionPerformed

private void txtDescontoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDescontoActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_txtDescontoActionPerformed

private void codigo2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_codigo2ActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_codigo2ActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {

                new CxVenda().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Adicionar;
    private javax.swing.JTextField Nome_funcionario;
    private javax.swing.JButton bt_encerrar;
    private javax.swing.JButton bt_fechar;
    private javax.swing.JButton bt_printer;
    private javax.swing.JButton btnAtualizar;
    private javax.swing.JTextField codigo1;
    private javax.swing.JTextField codigo2;
    private javax.swing.JTextField dProduto;
    private javax.swing.JTextField data;
    private javax.swing.JTextField hora;
    private javax.swing.JButton jButton6;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField quant;
    private javax.swing.JTextField status;
    private javax.swing.JTable tblVenda;
    private javax.swing.JTextField tipo;
    private javax.swing.JTextField txtCover;
    private javax.swing.JTextField txtDesconto;
    private javax.swing.JTextField txtGarcom;
    private javax.swing.JTextField txtMesa;
    private javax.swing.JTextField txtP;
    private javax.swing.JTextField txtSubTotal;
    private javax.swing.JTextField txtTotal;
    private javax.swing.JTextField valor;
    // End of variables declaration//GEN-END:variables
}